// com/example/teacherservice/controller/TeacherCourseController.java
package com.example.teacherservice.controller;

import com.example.teacherservice.dto.TeacherCourseDetailDTO;
import com.example.teacherservice.service.TeacherCourseService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/spoc/vod/teacher/course")
public class TeacherCourseController {

    private final TeacherCourseService teacherCourseService;

    public TeacherCourseController(TeacherCourseService teacherCourseService) {
        this.teacherCourseService = teacherCourseService;
    }

    /**
     * 获取课程详情（教师视角）
     */
    @GetMapping("/{courseId}/detail")
    public ResponseEntity<TeacherCourseDetailDTO> getCourseDetail(@PathVariable Long courseId) {
        TeacherCourseDetailDTO detail = teacherCourseService.getCourseDetail(courseId);
        return ResponseEntity.ok(detail);
    }

    /**
     * 添加学生到课程
     */
    @PostMapping("/{courseId}/students")
    public ResponseEntity<?> addStudentToCourse(
            @PathVariable Long courseId,
            @RequestParam Long studentId) {
        try {
            teacherCourseService.addStudentToCourse(courseId, studentId);
            return ResponseEntity.ok().build();
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }

    /**
     * 从课程中移除学生
     */
    @DeleteMapping("/{courseId}/students/{studentId}")
    public ResponseEntity<?> removeStudentFromCourse(
            @PathVariable Long courseId,
            @PathVariable Long studentId) {
        try {
            teacherCourseService.removeStudentFromCourse(courseId, studentId);
            return ResponseEntity.ok().build();
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }
}